package cn.edu.dgut.sai.jpa;

import lombok.Value;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 订单存储库
 *
 * @author Sai
 * Created by Sai on 2019/9/15.
 */
public interface OrderRepository extends JpaRepository<Order, Integer>,
        JpaSpecificationExecutor<Order> {

    List<Order> getOrderByName(String name);

    List<OrderDTO> findByName(String name);

    List<OrderDTO1> getByName(String name);

    <U> List<U> getOrderByName(String name, Class<U> type);

    @Query("select o from Order o where o.name = ?1")
    List<Order> getOrderByName1(String name);

    @Query(value = "select * from t_order where name = ?1",nativeQuery = true)
    List<Order> getOrderByName2(String name);
}

interface OrderDTO{
    String getName();
}

// 利用Lombok的@Value,构造返回类型DTO
@Value
class OrderDTO1{
   String name;
}
